//
//  DetailJeuxView.m
//  xKey Interface
//
//  Created by Guillaume SOURDRILLE on 19/02/12.
//  Copyright (c) 2012 Edenyorke. All rights reserved.
//

#import "DetailJeuxView.h"
#import "URLConnection.h"
#import "DataXmlParser.h"

@implementation DetailJeuxView
@synthesize descriptionLabel;
@synthesize imageJeu, nomJeu, urlConnection, actionSheet;


- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void) setParam:(NSString*) nom: (NSString*) ident :(UIImage*) image : (NSString*) description{
           
        imageJeuParam = image;
        nomJeuxParam = nom;
        idJeuParam = ident;
        descriptionJeu = description;
    
}

- (void)didReceiveMemoryWarning
{
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];
    
    // Release any cached data, images, etc that aren't in use.
}

#pragma mark - View lifecycle

- (void)viewDidLoad
{
    [super viewDidLoad];
    imageJeu.image = imageJeuParam;
    nomJeu.text = nomJeuxParam;
    backButton.title = NSLocalizedString(@"detail.back.button", @"");
    [launchButton setTitle:NSLocalizedString(@"detail.launch.button", @"") forState:UIControlStateNormal];
    if (descriptionJeu != nil){
        descriptionLabel.text = descriptionJeu;
        
    }else{
        descriptionLabel.text = NSLocalizedString(@"detail.no.decription", @"");
    }
    [self initConnection];
}

- (void)viewDidUnload
{
    
    launchButton = nil;
    backButton = nil;
    [self setDescriptionLabel:nil];
    [super viewDidUnload];
    imageJeu = nil;;
    nomJeu = nil;
    urlConnection = nil;
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    // Return YES for supported orientations
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}


-(void) launchGame{
        
        NSURL *url = [urlConnection getURLForLaunchGame:idJeuParam];
        DataXmlParser *xmlParser = [[DataXmlParser alloc]init];
        NSString *trayState = [xmlParser launchGame:url];
        
        if ([trayState boolValue]){
            actionSheet = [[UIActionSheet alloc] initWithTitle:NSLocalizedString(@"actionsheet.title", @"")
                                                      delegate:self
                                             cancelButtonTitle:NSLocalizedString(@"actionsheet.button.quit", @"")
                                        destructiveButtonTitle:nil
                                             otherButtonTitles:NSLocalizedString(@"actionsheet.button.reload", @""),nil];
            [actionSheet showInView:self.view];
         
            
        }  
    }
    
-(void)actionSheet:(UIActionSheet *)action clickedButtonAtIndex:(NSInteger)buttonIndex {
    if (buttonIndex == 0) {
            [self launchGame];
        } 
}
    


- (void)initConnection {
    
    urlConnection = [[URLConnection alloc] initWithIp];
}

- (IBAction)launchGame:(id)sender {
}

- (void)processRetour{
     [self dismissModalViewControllerAnimated:YES];
}


@end
